#include <iostream>
using std::cout;
using std::endl;

class Base{
public:
    Base(long x)
    : _base(x)
    {}

    virtual void display() const{
        cout << "Base::display()" << endl;
    }
private:
    long _base;
};


class Derived
: public Base
{
public:
    Derived(long base,long derived)
    : Base(base)
    , _derived(derived)
    {}

    //基类的display是虚函数
    //派生类中的display如果满足覆盖的条件
    //(派生类中定义的虚函数的形式与基类中虚函数的形式完全一致)
    //那么自动地也是虚函数
    void display() const override{
        cout << "Derived::display()" << endl;
    }
private:
    long _derived;
};

void test0(){
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;
    cout << endl;


    Derived d1(2,5);
    Base * pb = &d1;
    pb->display();

    Base base(10);
    Base * pb2 = &base;
    pb2->display();
}

int main(void){
    test0();
    return 0;
}
